home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Info-Mac 4
/
Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso
/
Development
/
Source
/
DBL Pascal Library
/
LayerMgr
/
LayerMgr_Test ƒ
/
LayerMgr_Test.p
next >
Wrap
Text File
|
1993-02-15
|
2KB
|
97 lines
program LayerMgr_Test;
uses
Layers;
type
{Parameters to our LayerActionProc}
FindLayerParmRec = record
findPSN: ^ProcessSerialNumber;
foundLayer: LayerPtr;
end;
FindLayerParmPtr = ^FindLayerParmRec;
{FindLayerProcess: a LayerActionProc that looks for a specific PSN}
function FindLayerProcess (theWindow: WindowPtr; theLayer: LayerPtr; refCon: Longint): WindowActionCode;
var
code: WindowActionCode;
info: LayerInfoPtr;
p: FindLayerParmPtr;
err: OSErr;
same: Boolean;
begin
{Assume we'll be going to the next layer}
code := kNextLayer;
{If this window is really a layer, use it and go to the next "window"}
if IsLayer(theWindow) then
begin
theLayer := theWindow;
code := kNextWindow;
end;
{If we got a layer…}
if theLayer <> nil then
begin
{…with some info…}
info := LayerInfoPtr(GetWRefCon(theLayer));
if info <> nil then
begin
{…see if the PSNs match}
p := FindLayerParmPtr(refCon);
err := SameProcess(info^.layerPSN, p^.findPSN^, same);
if same then {They match}
begin
p^.foundLayer := theLayer;
code := kBreak;
end;
end;
end;
FindLayerProcess := code;
end;
{ProcessLayer: find a process' layer by its PSN}
function ProcessLayer (psn: ProcessSerialNumber): LayerPtr;
var
p: FindLayerParmRec;
code: WindowActionCode;
begin
p.findPSN := @psn;
p.foundLayer := nil;
code := ForEachLayerWindowDo(DeskLayer, LayerPtr(kAllLayers), LayerPtr(nil), @FindLayerProcess, Longint(@p));
ProcessLayer := p.foundLayer;
end;
var
aPSN: ProcessSerialNumber;
err: OSErr;
aLayer: LayerPtr;
aWindow: WindowPtr;
aTitle: Str255;
begin
{Test program walks through all the processes in the system. For each one found,}
{print its layer’s name and visibility and the name and visibility of all its windows.}
ShowText;
with aPSN do
begin
lowLongOfPSN := kNoProcess;
highLongOfPSN := kNoProcess;
end;
err := GetNextProcess(aPSN);
repeat
aLayer := ProcessLayer(aPSN);
if aLayer <> nil then
begin
writeln(GetLayerName(aLayer), ' ', LayerVisible(aLayer));
aWindow := LayerFrontWindow(aLayer);
while aWindow <> nil do
begin
GetWTitle(aWindow, aTitle);
writeln(' ', aTitle, ' ', WindowPeek(aWindow)^.visible);
aWindow := WindowPtr(WindowPeek(aWindow)^.nextWindow);
end;
end;
err := GetNextProcess(aPSN);
until err <> noErr;
end.